package net.zjitc.myqueue.myservice;

import net.zjitc.myqueue.MyQu;
import net.zjitc.myqueue.exception.MyQuException;

/**
 * Created by Administrator on 2017/4/6.
 */
public class WindowsService extends Thread{
    private MyQu<Integer> queue; //由机器产生的队列拿过来的

    public WindowsService(MyQu<Integer> queue) {
            this.queue = queue;
    }

    /*每隔5秒处理一个*/
    @Override
    public void run() {
        while (true){
            //取数字
            synchronized (queue) { //同步
                try {
                    Integer callNum = queue.remove();
                    System.out.println("请" + callNum + "号到"+Thread.currentThread().getName()+"窗口处理业务");
                } catch (MyQuException e) {
                    //System.out.println(e.getMessage());
                }
            }
            try {
                Thread.sleep(5000);
            } catch (InterruptedException e) {
                System.out.println(e.getMessage());
            }
        }
    }
}
